package model;

import static org.junit.Assert.*;

import org.junit.Test;

public class AdviceTest {

	
	@Test
	public void isAdvice(){
		SysAdvice a = new SysAdvice(true,"ajc$","return type","public");
		assertTrue(SysAdvice.isAdvice(a));
		SysMethod m = new SysMethod(true,"ajc$", "Z", "private");
		assertTrue(SysAdvice.isAdvice(m));
		m = new SysMethod(true,"","","");
		a = new SysAdvice(true,"","","");
		assertFalse(SysAdvice.isAdvice(a));
		assertFalse(SysAdvice.isAdvice(m));
	}
	
	@Test
	public void makeAdvice(){
		SysAdvice after = new SysAdvice(true,"$after$","","");
		SysAdvice after_t = new SysAdvice(true,"$afterThrowing","","");
		SysAdvice after_r = new SysAdvice(true,"$afterReturning","","");
		SysAdvice around = new SysAdvice(true,"$around","","");
		SysAdvice before = new SysAdvice(true,"$before","","");
		SysAdvice inter_m = new SysAdvice(true,"$interMethod","","");
		assertTrue(after.getAdviceType().equals("after"));
		assertTrue(after_t.getAdviceType().equals("after_t"));
		assertTrue(after_r.getAdviceType().equals("after_r"));
		assertTrue(before.getAdviceType().equals("before"));
		assertTrue(around.getAdviceType().equals("around"));
		assertTrue(inter_m.getAdviceType().equals("inter_method"));
	}
	
	@Test
	public void affects(){
		SysAdvice a = new SysAdvice(true,"","","");
		SysMethod m = new SysMethod(true,"","","");
		assertFalse("should not affects this method", a.affects(m));
		a.addAffected(m);
		assertTrue("should affect this method", a.affects(m));
		
	}
	

}
